<template>
  <div class="home">
    <van-nav-bar
      title="确认订单"
      class="nav_bar"
      fixed
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="vip">
      <div class="top">
        <van-image
          class="top_icon"
          :src="require('@/assets/icon/common/vip_3.png')"
        />
        <span class="title">{{ skuInfo.goodsName }}</span>
      </div>
      <div class="bottom">
        <!-- <div class="text_1">
          全年预计省<span class="large">XXXXX</span>元/年
        </div> -->
        <div class="text_2">具体可用门店以界面展示为准</div>
      </div>
      <div class="circle" @click="showRoule">
        <div>查看</div>
        <div>权益规则></div>
      </div>
      <div class="vip_tips">大会员</div>
    </div>
    <div class="cell">
      <van-cell-group>
        <van-cell>
          <template #title>
            <div class="cell_label">安心修大会员</div>
          </template>
          <template>
            <div class="cell_value">
              待付款：￥{{ orderInfo.priceDetailDTO?.flowPrice }}
            </div>
            <div class="small_value">x1</div>
          </template>
        </van-cell>
        <van-cell :border="false">
          <template #title>
            <div class="cell_label">使用期限</div>
          </template>
          <template>
            <div class="cell_value">购卡后365天内</div>
          </template>
        </van-cell>
        <!-- <van-cell :border="false">
          <template #title>
            <div class="cell_label">优惠券</div>
          </template>
          <template>
            <div class="cell_value" @click="showPopup">无可用优惠券></div>
          </template>
        </van-cell> -->
        <!-- <van-cell :border="false">
          <template #title>
            <div class="cell_label">积分</div>
          </template>
          <template>
            <div class="cell_value">折扣xx.xxx元></div>
          </template>
        </van-cell> -->
        <van-cell :border="false">
          <template>
            <div class="cell_red">合计:￥{{ orderInfo.price }}</div>
          </template>
        </van-cell>
      </van-cell-group>
    </div>
    <!-- <div class="cell">
      <van-cell-group>
        <van-cell>
          <template #title>
            <div class="cell_title">会员卡关联车辆</div>
          </template>
        </van-cell>
        <van-cell :border="false" is-link>
          <template #title>
            <div class="cell_label_2">浙E·23E0A 领克1.5TD双离合 劲Plus ></div>
          </template>
        </van-cell>
        <van-cell v-if="false" :border="false">
          <template>
            <div class="cell_btn">
              <div class="cell_box">绑定车辆</div>
            </div>
          </template>
        </van-cell>
      </van-cell-group>
    </div> -->
    <div class="bottom_pay">
      <div class="text_3">
        支付即阅读并同意<span class="text_red" @click="showPolicy"
          >《安心修会员服务协议》</span
        >
      </div>
      <div class="pay">
        <div class="price">
          <span>合计</span>
          <span class="large_red">￥{{ orderInfo.price }}</span>
        </div>
        <div class="pay_btn" @click="goToPay">去支付</div>
      </div>
    </div>
    <van-popup v-model="show" position="bottom" round>
      <div class="rules_content">
        <span class="close" @click="show = false">
          <van-icon name="cross" size="20" color="#000" />
        </span>
        <div class="rules_imgs">
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/07/31/0d0b6b7160cf2678eb7a0dfab313a367.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/07/31/d32b1d2186649aaeaf7429c69232f415.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/07/31/67e6a41fe0e418759bde2eb95f26aafd.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/07/31/2e44d67294e41026c0e2ce71f7aacd72.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/07/31/a6e0495ac05a07746f2dd6a08fd89e4f.jpg"
            alt=""
          />
        </div>
      </div>
    </van-popup>
    <van-popup
      v-model="showCouponList"
      round
      position="bottom"
      style="height: 80%; padding-top: 4px"
    >
      <van-tabs v-model="active" color="#447ecc">
        <van-tab title="可用"></van-tab>
        <van-tab title="不可用"></van-tab>
      </van-tabs>
      <div style="padding: 20px">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <OrderCoupon v-for="i in 3" :key="i"></OrderCoupon>
        </van-list>
      </div>

      <div class="button">不使用</div>
    </van-popup>
    <van-dialog v-model="show2" show-cancel-button>
      <div
        style="display: flex; justify-content: center; padding: 80px 0 80px 0"
      >
        <QRCode v-if="paySrc" ref="qr" :url="paySrc"></QRCode>
      </div>
    </van-dialog>
    <van-popup v-model="show3" position="bottom" round>
      <div class="rules_content">
        <span class="close" @click="show3 = false">
          <van-icon name="cross" size="20" color="#000" />
        </span>
        <div class="rules_imgs">
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/08/06/12ca44490c8a1d949e8dda01a2886c81.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/08/06/c471a79a8e93f2d5dbeefa6f463a1bfd.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/08/06/a013e9bef271a449e2e1cc8d951c00cf.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/08/06/1f43ad08cf4d1fbb47ed707e138acfc1.jpg"
            alt=""
          />
          <img
            src="https://zxcxappimg.cxbtv.cn/qinghai/2025/08/06/644383fac2468090983b4c7969d96dcc.jpg"
            alt=""
          />
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import OrderCoupon from "@/components/order_coupon.vue";
import QRCode from "@/components/qrCode.vue";
import { Toast } from "vant";
import api from "@/api/api";
import { isZxcxApp } from "@/utils/common";
export default {
  components: { OrderCoupon, QRCode },
  props: {},
  data() {
    return {
      show: false,
      show2: false,
      show3: false,
      couponList: [],
      showCouponList: false,
      active: 0,
      loading: false,
      finished: true,
      query: {},
      loading2: false,
      orderInfo: {},
      skuInfo: {},
      paySrc: "",
    };
  },
  watch: {},
  computed: {},
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    showRoule() {
      this.show = true;
    },
    showPopup() {
      this.showCouponList = true;
    },
    onLoad() {},
    async getOrderDetail() {
      Toast.loading({
        duration: 0,
        forbidClick: true,
        message: "加载中",
      });
      this.orderInfo = await api.buyNow(this.query).finally(() => {
        Toast.clear();
      });
      this.skuInfo = this.orderInfo.skuInfoList[0].skuList[0];
    },
    showPolicy() {
      this.show3 = true;
    },
    async goToPay() {
      this.$toast.loading({
        message: "加载中",
      });
      let res = await api.createTrade({
        settleId: this.orderInfo.settleId,
      });
      let res2 = await api
        .pay({
          sn: res.sn,
        })
        .catch((err) => {
          console.log(err);
        });
      this.$toast.clear();
      if (res2) {
        if (isZxcxApp()) {
          window.location.href = res2;
        } else {
          this.show2 = true;
          this.paySrc = res2;
        }
      } else {
        this.$toast.fail({
          message: "支付失败",
        });
      }
    },
  },
  created() {
    this.query.goodsId = this.$route.query.goodsId;
    this.query.num = Number(this.$route.query.num);
    this.query.skuId = this.$route.query.skuId;
    this.getOrderDetail();
  },
  mounted() {},
};
</script>
<style lang="less" scoped>
.home {
  min-height: 100vh;
  background-color: #f8f8f8;
  padding: 200px 50px 380px 50px;
  .nav_bar {
    /deep/ .van-icon {
      font-size: 50px;
      font-weight: bold;
      color: #333333;
    }
  }
  .vip {
    height: 425px;
    border-radius: 20px;
    background: url("https://zxcxappimg.cxbtv.cn/qinghai/2025/05/06/934c07ab0dfeb980654ec2d0481338f6.png")
      no-repeat;
    background-size: cover;
    background-position: top center;
    position: relative;
    padding: 90px 50px 50px;
    box-sizing: border-box;
    .top {
      display: flex;
      align-items: center;
      .top_icon {
        width: 75px;
        height: 61px;
      }
      .title {
        font-size: 70px;
        color: #53290b;
        margin-left: 10px;
        font-weight: bold;
        letter-spacing: 10px;
      }
    }
    .bottom {
      margin-top: 60px;
      .text_1,
      .text_2 {
        font-size: 50px;
        color: #53290b;
        .large {
          font-size: 60px;
          font-weight: bold;
        }
      }
      .text_2 {
        margin-top: 0.8rem;
      }
    }
    .circle {
      position: absolute;
      width: 204px;
      height: 204px;
      border-radius: 102px;
      background: linear-gradient(to bottom, #71350a, #aa5517);
      right: 51px;
      bottom: 80px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      color: #fff;
      font-size: 32px;
      padding: 20px;
    }
    .vip_tips {
      position: absolute;
      top: 0;
      right: 0;
      height: 51px;
      padding: 0 25px;
      font-size: 34px;
      color: #fde9d8;
      background: linear-gradient(to bottom, #71350a, #000000);
      border-radius: 25px 20px 0 25px;
    }
  }
  .cell {
    margin-top: 30px;
    .cell_title {
      font-size: 52px;
      color: #000;
      font-weight: bold;
    }
    .cell_label {
      font-size: 46px;
      color: #999999;
    }
    .cell_label_2 {
      font-size: 46px;
      color: #333333;
    }
    .cell_value {
      font-size: 46px;
      color: #333333;
    }
    .small_value {
      font-size: 38px;
      color: #858585;
      text-align: right;
    }
    .cell_red {
      font-size: 46px;
      color: #d60000;
      font-weight: bold;
      text-align: right;
    }
    .cell_btn {
      display: flex;
      justify-content: center;
      .cell_box {
        height: 110px;
        padding: 0 124px;
        line-height: 110px;
        text-align: center;
        color: #d38d53;
        font-size: 46px;
        border-radius: 20px;
        border: 1px solid #d38d53;
      }
    }
  }
  .bottom_pay {
    min-height: 366px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    .text_3 {
      padding: 23px 50px;
      font-size: 42px;
      color: #999999;
      .text_red {
        font-size: 42px;
        color: #d92121;
      }
    }
    .pay {
      background: #fff;
      padding: 60px 54px 120px 54px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .price {
        font-size: 46px;
        color: #1d1d1d;
        .large_red {
          font-size: 60px;
          color: #d60000;
          font-weight: bold;
        }
      }
      .pay_btn {
        height: 116px;
        background: #d92121;
        border-radius: 58px;
        padding: 0 106px;
        line-height: 116px;
        text-align: center;
        color: #fff;
        font-size: 52px;
      }
    }
  }
  .rules_content {
    width: 100%;
    height: 80vh;
    position: relative;
    .close {
      position: absolute;
      right: 0.5rem;
      top: 0.5rem;
      font-size: 18px;
    }
    .rules_imgs {
      display: flex;
      flex-direction: column;
      justify-content: center;
      img {
        font-size: 0;
        line-height: 1;
      }
    }
  }

  .button {
    width: 70%;
    font-size: 50px;
    color: white;
    background-color: #3985f7;
    padding: 20px 0;
    margin: 0 auto;
    text-align: center;
    border-radius: 64px;
  }
}
</style>